package org.breathe.dynamic.thread.pool.core.designpattern.strategy.impl.alarmstrategy;

import cn.hutool.core.collection.CollUtil;
import org.breathe.dynamic.thread.pool.core.designpattern.strategy.AlarmStrategy;
import org.breathe.dynamic.thread.pool.core.thread.BreatheDtpExecutor;
import org.breathe.thread.pool.common.entity.NotifyItem;

import java.util.Objects;

/**
 * 拒绝报警策略
 * @author: breathe
 * @createTime: 2025-04-13
 */
public class RejectAlarmStrategy implements AlarmStrategy {
    @Override
    public boolean check(BreatheDtpExecutor executor, NotifyItem notifyItem) {
        if (Objects.isNull(notifyItem)) {
            return false;
        }
        int rejectCount = executor.getRejectCount();
        return satisfyBaseCondition(notifyItem) && rejectCount >= notifyItem.getThreshold();
    }

    private boolean satisfyBaseCondition(NotifyItem notifyItem) {
        return notifyItem.isEnabled() && CollUtil.isNotEmpty(notifyItem.getPlatforms());
    }
}
